*** Settings ***
Documentation    TC13-Reports Generation FCL
Resource    ../../Keywords/Common_Head.robot
Force Tags    P3
Metadata    Author    Joe
Metadata    ID    6855121


*** Test Cases ***
TC13-Reports Generation FCL
    Step 1 User Goes To Reports Success Ratio Report
    Step 2 Select FCL
    Step 3 Go To Rate Comparison Report
    Step 4 Select RFQ Launch Date From 2024 01 01
    Step 5 Go To Deadline Time Report
    Step 6 Select RFQ Launch Date From 2024 01 012
    Step 7 Click On Download Button
    Step 8 Go To Transit Time Report
    Step 9 Select RFQ Launch Date From 2024 01 013



*** Keywords ***
Step ${step} User Goes To Reports Success Ratio Report
    #************************Step 1******************************
    #  Do:
    #      User goes to Reports Success Ratio Report
    #  Expected:
    #      Success Ratio Report page is displayed as
    #      index php attachments get f872442b a63f 4437 961c
    #     b8cfa2e2fe2a
    #************************************************************
    Login Space
    Navigation Space    Reports    Success Ratio Report
    Wait For Elements State    //label[.='Basic Currency']    visible    60 
    Sleep    3
    

Step ${step} Select FCL
    #************************Step 2******************************
    #  Do:
    #      Select FCL
    #      RFQ Launch Date from 2022 01 01
    #      Select General Report Detailed Report
    #      Click on Generate Report
    #      Check the downloaded file
    #  Expected:
    #      After a few minutes the file format is downloaded like
    #     attached index php attachments get 293f8d7b dcc6 46d5
    #     99f3 c34046b873ba
    #************************************************************
    click    //input[@value="FCL"]
    select options by    ${report_RFQ_Date_Type}     text    RFQ Launch Date
    Fill Text    ${report_RFQ_Date_From}    01/01/2022
    Click    ${report_General_Report_Checkbox}
    Click    ${report_Detailed_Report_Checkbox}   
    # Sleep    3
    # ${filename}    Download File    ${report_Generate_Report}
    # Sleep    20
    ${DOWNLOAD_PATH}     Normalize Path    ${DOWNLOAD_PATH}
    ${filename}    Set Variable    ${DOWNLOAD_PATH}${/}report.xlsx
    Set Test Variable    ${filename}    ${filename}
    ${dl_promise}    Promise To Wait For Download    ${filename}
    sleep    1
    Wait Until Keyword Succeeds    10x    400ms    Click     ${report_Generate_Report}
    Sleep    30s
    Wait Until Keyword Succeeds    20x    3s        Directory Should Not Be Empty    ${DOWNLOAD_PATH}
    Wait Until Keyword Succeeds    10x    400ms    Copy File    ${DOWNLOAD_PATH}${/}*    ${filename}
    Open Excel Document     ${filename}    General Report FCL
    ${Column}    Read Excel Column    3
    ${data}    Read Excel Column    4
    ${COLNUM}    Get Length    ${Column} 
    ${ROW}    Read Excel Row    17
    ${ROWNUM}    Get Length    ${ROW} 
    Close All Excel Documents
    Open Excel Document    ${CURDIR}${/}TestData${/}FCL Success Ratio_Reporting_09112024_JB.xlsx  General Report FCL
    ${Column2}    Read Excel Column    3
    ${data2}    Read Excel Column    4
    ${COLNUM2}    Get Length    ${Column2} 
    ${ROW2}    Read Excel Row    17
    ${ROWNUM2}    Get Length    ${ROW2} 
    Close All Excel Documents
    Should Be Equal    ${COLNUM}    ${COLNUM2}
    Should Be Equal     ${ROWNUM}   ${ROWNUM2}
    Wait Until Search Finished
    Close All Excel Documents
    Remove File    ${filename}
    Empty Directory    ${DOWNLOAD_PATH}
Step ${step} Go To Rate Comparison Report
    #************************Step 3******************************
    #  Do:
    #      Go to Rate Comparison Report
    #  Expected:
    #      The page is displayed like
    #      index php attachments get 2db805bc d6c6 4e14 867b
    #     78bf3e854431
    #************************************************************
    Click    ${navigation_Rate_Comparison_Report}
    Wait For Elements State    ${title_Rate_Comparison_Report}    enabled    60
    Wait For Elements State    ${report_Air}
    Wait For Elements State    ${report_FCL}
    Wait For Elements State    ${report_LCL}
    Wait For Elements State    ${report_upload}
    Wait For Elements State    ${report_RFQ_Date_Type}   
    Wait For Elements State    ${report_Rate_Comparison_Basic_Currency}  
    Wait For Elements State    ${report_vertical_Market}   
    Wait For Elements State    ${report_customer}    
    Wait For Elements State    ${report_origin_Region}    
    Wait For Elements State    ${report_destination_Region}  
    Wait For Elements State    ${report_origin_Cluster}   
    Wait For Elements State    ${report_destination_Cluster}   
    Wait For Elements State    ${report_origin_Country}    
    Wait For Elements State    ${report_destination_Country}    
    Wait For Elements State    ${report_origin_Airport} 
    Wait For Elements State    ${report_destination_Airport}   
    Wait For Elements State    ${report_origin_Gateway}   
    Wait For Elements State    ${report_destination_Gateway}   
    Wait For Elements State    ${report_service_Level}  
    Wait For Elements State    ${report_Reset}
    # Customer Data tab in Rate Comparison Report
    Wait For Elements State    ${report_Rate_Comparison_Customer_Data_Tab}   
    Wait For Elements State    ${report_Rate_Comparison_Origin_Charges_Tab}   
    Wait For Elements State    ${report_Rate_Comparison_Airfreight_and_Charges_Tab}    
    Wait For Elements State    ${report_Rate_Comparison_Destination_Charges_Tab}    
    Wait For Elements State    ${report_Rate_Comparison_Airfreight_and_Charges_Tab}  
    Wait For Elements State    ${report_Rate_Comparison_Lane_Number}   
    Wait For Elements State    ${report_Rate_Comparison_Postal_Code} 
    Wait For Elements State    ${report_Rate_Comparison_Commodity}    
    Wait For Elements State    ${report_Rate_Comparison_Volume_as_per_validity_period} 
    Wait For Elements State    ${report_Rate_Comparison_Remarks}    
    Wait For Elements State    ${report_Rate_Comparison_Remarks}   
    Wait For Elements State    ${report_Rate_Comparison_Customer_Target_Information}   
    Wait For Elements State    ${report_Rate_Comparison_Service Level Customer}    
    Wait For Elements State    ${report_Rate_Comparison_Description}  
    Wait For Elements State    ${report_Generate_Report} 
    # Origin Charges tab in Rate Comparison Report
    Click    ${report_Rate_Comparison_Origin_Charges_Tab}  
    Wait For Elements State    ${report_Rate_Comparison_Pick_up_Charges}   
    # Airfreight and Charges tab in Rate Comparison Report
    Click    ${report_Rate_Comparison_Airfreight_and_Charges_Tab}   
    Wait For Elements State    ${report_Rate_Comparison_Airfreight_Rate}   
    # Destination Linehaul tab in Rate Comparison Report
    Click    ${report_Rate_Comparison_Destination_Linehaul_Tab}    
    Wait For Elements State    ${report_Rate_Comparison_In-Transit_Handling}    
    Wait For Elements State    ${report_Rate_Comparison_Destination Linehaul}   
    # Destination Charges tab in Rate Comparison Report
    Click    ${report_Rate_Comparison_Destination_Charges_Tab}   
    Wait For Elements State    ${report_Rate_Comparison_Delivery_Charges}    
    Wait For Elements State    ${report_Rate_Comparison_Delivery_Transit_Time_in_hours}    
Step ${step} Select RFQ Launch Date From 2024 01 01
    #************************Step 4******************************
    #  Do:
    #      Select RFQ Launch Date from 2024 01 01
    #      Select all checkboxes
    #      Click on Generate Report button
    #      Check the downloaded file
    #  Expected:
    #      After a few minutes the file is downloaded like
    #     attached index php attachments get c293ca4a 3dcb 42dd
    #     9f3e f4b406331b39
    #************************************************************
    select options by    ${report_RFQ_Date_Type}     text    RFQ Launch Date
    CLICK    ${report_FCL}
    Sleep    2      

    # Check All Check Box for Report    group ng-scope
    Check All Check Box for Page    //section[@class="group ng-scope"]
    
    # ${uncheckedStatus}    Run Keyword And Return Status    Get Element States    //label[@data-uib-tooltip="Customer Consolidation Drayage"]/input    contains    unchecked
    # IF    '${uncheckedStatus}' == 'True'
    #     Click   (//label[@data-uib-tooltip="Customer Consolidation Drayage"]/input)[1]
    # ELSE
    #     Repeat Keyword    2    Click    //label[@data-uib-tooltip="Customer Consolidation Drayage"]/input
    # END
    # Repeat Keyword    2    Click    //label[@data-uib-tooltip="On-Carriage (Freight)"]/input
    ${uncheckedStatus}    Run Keyword And Return Status    Get Element States    //label[@data-uib-tooltip="Customer Consolidation Unstuffing Charges"]/input    contains    unchecked
    IF    '${uncheckedStatus}' == 'True'
        Click   //label[@data-uib-tooltip="Customer Consolidation Unstuffing Charges"]/input
    ELSE
        Repeat Keyword    2    Click    //label[@data-uib-tooltip="Customer Consolidation Unstuffing Charges"]/input
    END   
    ${uncheckedStatus}    Run Keyword And Return Status    Get Element States    //label[@data-uib-tooltip="Container Storage at Destination"]/input    contains    unchecked
    IF    '${uncheckedStatus}' == 'True'
        Click   //label[@data-uib-tooltip="Container Storage at Destination"]/input
    ELSE
        Repeat Keyword    2    Click    //label[@data-uib-tooltip="Container Storage at Destination"]/input
    END   
    click    //label[@data-uib-tooltip="TOTAL Transit Time"]/input
    Repeat Keyword    2    Click    //label[@data-uib-tooltip="On-Carriage (Freight)"]/input
    Click    (//label[@data-uib-tooltip="Customer Consolidation Drayage"]/input)[2]


    click    //a[contains(text(),'Carrier/Port Related Destination Charges')]
    click    //span[@data-uib-tooltip="Duration From Vessel Arrival until Gate-Out in Days"]/..//input
    click    //label[@data-uib-tooltip="Free Out Charge (if applicable)"]/input

    click    //a[contains(text(),'Demurrage & Detention')]
    click    //label[@data-uib-tooltip="Requested Origin Demurrage"]/input
    click    //label[@data-uib-tooltip="Requested Origin Detention"]/input
    click    //label[@data-uib-tooltip="Requested Origin Dem/Det"]/input
    click    //label[@data-uib-tooltip="DB SCHENKER Origin Demurrage"]/input
    click    //label[@data-uib-tooltip="DB SCHENKER Origin Detention"]/input
    click    //label[@data-uib-tooltip="DB SCHENKER Origin Dem/Det"]/input
    click    //label[@data-uib-tooltip="Requested Destination Demurrage"]/input
    click    //label[@data-uib-tooltip="Requested Destination Detention"]/input
    click    //label[@data-uib-tooltip="Requested Destination Dem/Det"]/input
    click    //label[@data-uib-tooltip="DB SCHENKER Destination Demurrage"]/input
    click    //label[@data-uib-tooltip="DB SCHENKER Destination Detention"]/input
    click    //label[@data-uib-tooltip="DB SCHENKER Destination Dem/Det"]/input

    click    //a[contains(text(),'Ocean Transport Charges')]
    Repeat Keyword    2    click    //label[@data-uib-tooltip="Ocean Freight & Charges"]/input
    Repeat Keyword    2    click    //label[@data-uib-tooltip="OCEAN FREIGHT"]/input
    Repeat Keyword    2    click    //label[@data-uib-tooltip="BAF Bunker Adjustment"]/input
    Repeat Keyword    2    click    //label[@data-uib-tooltip="Ocean Freight Service Details"]/input
    click    //label[@data-uib-tooltip="Sailing Information"]/input
    click    //label[@data-uib-tooltip="Filing Reference"]/input
    

    click    //a[contains(text(),'Carrier/Port Related Origin Charges')]
    click    //label[@data-uib-tooltip="Free in Charge (if applicable)"]/input
    click    //label[@data-uib-tooltip="Transit Time"]/input


    click    //a[contains(text(),'Pre-Carriage & Origin Local Charges')]
    Repeat Keyword    2    click    //label[@data-uib-tooltip="Origin Pre-Carriage"]/input
    Repeat Keyword    2    click    //label[@data-uib-tooltip="Other Origin Charges"]/input
    click    //label[@data-uib-tooltip="Customer Consolidation Stuffing Charges"]/input
    click    //label[@data-uib-tooltip="Customer Consolidation Drayage"]/input
    click    //label[@data-uib-tooltip="Container Storage at Origin"]/input


    click    //a[contains(text(),'Customer Data')]
    click    //label[@data-uib-tooltip="Lane Number"]/input
    click    //label[@data-uib-tooltip="Reefer Information"]/input
    click    //label[@data-uib-tooltip="Postal Code"]/input
    click    //label[@data-uib-tooltip="Customer's Delivery"]/input
    Repeat Keyword    2    click    //label[@data-uib-tooltip="Volume (as per validity period)"]/input
    Click    //label[@data-uib-tooltip="Commodity"]/input
    Click    //label[@data-uib-tooltip="Customer Target Information"]/input
    # Fill Text    ${report_RFQ_Date_From}    01/01/2024
     ${filename}    Download File    ${report_Generate_Report}
    Sleep    20
    ${exp_report}    Set Variable    ${CURDIR}${/}TestData${/}FCL Rate Comparison Report11122024-043613.xlsx
    Compare Excel Value     ${filename}    ${exp_report}    14    4    startRow=5    startColumn=3
    Compare Excel Value    ${filename}    ${exp_report}    17    13    startRow=17    startColumn=3
    Close All Excel Documents
    Empty Directory    ${DOWNLOAD_PATH}
Step ${step} Go To Deadline Time Report
    #************************Step 5******************************
    #  Do:
    #      Go to Deadline Time Report
    #  Expected:
    #      The page is displayed like
    #      index php attachments get 800b5977 9ee2 4ae7 a1e5
    #     ed5c21d95211
    #************************************************************
    Click    ${navigation_Deadline_Time_Report}
    Wait For Elements State    ${title_Deadline_Time_Report}    enabled    10s
    Wait For Elements State    ${report_Air}
    Wait For Elements State    ${report_FCL}
    Wait For Elements State    ${report_LCL}
    Wait For Elements State    ${report_RFQ_Date_Type}     
    Wait For Elements State    ${report_vertical_Market}   
    Wait For Elements State    ${report_customer}    
    Wait For Elements State    ${report_Deadline_Time_Tender}    
    Wait For Elements State    ${report_Deadline_Time_region}    
    Wait For Elements State    ${report_Deadline_Time_country}    
    Wait For Elements State    ${report_Deadline_Time_Tender_Level_Label}    
    Wait For Elements State    ${report_Deadline_Time_Global_Checkbox}    
    Wait For Elements State    ${report_Deadline_Time_Region_Checkbox}    
    Wait For Elements State    ${report_Deadline_Time_Country_Checkbox}   
    Wait For Elements State    ${report_Deadline_Time_Cluster} 
    Wait For Elements State    ${report_Reset}  
    Wait For Elements State    ${report_Search}  

Step ${step} Select RFQ Launch Date From 2024 01 012
    #************************Step 6******************************
    #  Do:
    #      Select RFQ Launch Date from 2024 01 01
    #      Click on Search
    #  Expected:
    #      After a few seconds the page displays like
    #      index php attachments get 9c0ed9fd e83c 4927 bbb3
    #     fe739cda5af0
    #************************************************************
    CLICK    ${report_FCL}
    select options by    ${report_RFQ_Date_Type}     text    RFQ Launch Date
    Fill Text    ${report_RFQ_Date_From}    01/01/2024
    # Comment: For limit size of report, set Date_To as 01/02/2024
    # Fill Text    ${report_RFQ_Date_To}    01/02/2024
    Click    ${report_Search} 
    Sleep    10s
    Wait Until Keyword Succeeds    20x    3s    Check Search Result Count in Deadline Time Report

Step ${step} Click On Download Button
    #************************Step 7******************************
    #  Do:
    #      Click on Download button
    #  Expected:
    #      After a few seconds the file is downloaded like
    #     attached index php attachments get f76aed30 8727 467a
    #     a776 5d99988584e2
    #************************************************************
    Empty Directory    ${DOWNLOAD_PATH}
    ${DOWNLOAD_PATH}     Normalize Path    ${DOWNLOAD_PATH}
    ${report_download}    Set Variable    ${DOWNLOAD_PATH}${/}report_step7.xlsx
    Set Test Variable    ${report_download}    ${report_download}
    ${dl_promise}    Promise To Wait For Download    ${report_download}
    Wait Until Keyword Succeeds    10x    400ms    Click     ${report_Download_Button}
    Sleep    60s
    Wait Until Keyword Succeeds    20x    3s        Directory Should Not Be Empty    ${DOWNLOAD_PATH}
    # Wait Until Keyword Succeeds    10x    400ms    Copy File    ${DOWNLOAD_PATH}${/}*    ${report_download}
    ${exp_report}    Set Variable    ${CURDIR}${/}TestData${/}FCL Deadline Report _09112024_lo.xlsx 
    Compare Excel Value    ${report_download}    ${exp_report}    14    4    startRow=5    startColumn=3
    Compare Excel Value    ${report_download}    ${exp_report}    17    13    startRow=17    startColumn=3
    Close All Excel Documents
    Empty Directory    ${DOWNLOAD_PATH}

Step ${step} Go To Transit Time Report
    #************************Step 8******************************
    #  Do:
    #      Go to Transit Time Report
    #  Expected:
    #      The page is displayed like
    #      index php attachments get af73c0ff d5eb 490a b81f
    #     b047f3f426e7
    #************************************************************
    Click    ${navigation_Transit_Time_Report}
    Wait For Elements State    ${title_Transit_Time_Report}    enabled    10s
    Wait For Elements State    ${report_Air}
    Wait For Elements State    ${report_FCL}
    Wait For Elements State    ${report_LCL}
    Wait For Elements State    ${report_RFQ_Date_Type}
    Wait For Elements State    ${report_tender_status}
    Wait For Elements State    ${report_vertical_Market}      
    Wait For Elements State    ${report_customer}    
    Wait For Elements State    ${report_Origin_Region}    
    Wait For Elements State    ${report_destination_Region}   
    Wait For Elements State    ${report_Origin_Cluster}   
    Wait For Elements State    ${report_destination_Cluster}   
    Wait For Elements State    ${report_origin_Country}    
    Wait For Elements State    ${report_destination_Country}  
    Wait For Elements State    ${report_origin_Airport}   
    Wait For Elements State    ${report_destination_Airport}  
    Wait For Elements State    ${report_origin_Gateway}   
    Wait For Elements State    ${report_destination_Gateway}   
    Wait For Elements State    ${report_service_Level}  
    Wait For Elements State    ${report_Reset}  

Step ${step} Select RFQ Launch Date From 2024 01 013
    #************************Step 9******************************
    #  Do:
    #      Select RFQ Launch Date from 2024 01 01
    #      Click on Generate Report
    #  Expected:
    #      After a few seconds index php attachments get 67231e8c
    #     9dc6 4b9a 925e b7d049995929 the file is downloaded like
    #     attached
    #************************************************************
    CLICK    ${report_FCL}
    select options by    ${report_RFQ_Date_Type}     text    RFQ Launch Date
    Fill Text    ${report_RFQ_Date_From}    01/01/2024
    fill text    ${report_RFQ_Date_To}    31/12/2024
    # ${DOWNLOAD_PATH}     Normalize Path    ${DOWNLOAD_PATH}
    # ${report_download}    Set Variable    ${DOWNLOAD_PATH}${/}report_step9.xlsx
    # Set Test Variable    ${report_download}    ${report_download}
    # ${dl_promise}    Promise To Wait For Download    ${report_download}
    # Wait Until Keyword Succeeds    10x    1s    Click     ${report_Generate_Report}
    # Sleep    30s
    # Wait Until Keyword Succeeds    20x    3s        Directory Should Not Be Empty    ${DOWNLOAD_PATH}
    # Wait Until Keyword Succeeds    10x    1s    Copy File    ${DOWNLOAD_PATH}${/}*    ${report_download}
    ${report_download}    Download File    ${report_Generate_Report}
    Sleep    20s
    ${exp_report}    Set Variable    ${CURDIR}${/}TestData${/}FCL Transit Time Report_11122024_pc.xlsx
    Compare Excel Value    ${report_download}    ${exp_report}    17    2     FCL
    Compare Excel Value    ${report_download}    ${exp_report}    20    36    FCL    startRow=19  
    Close All Excel Documents
    Empty Directory    ${DOWNLOAD_PATH}

Check All Check Box for Report
    [Arguments]    ${sectionClass}
    Wait Until Search Finished
    Wait Until Search Finished
    ${Tabindex}    Set Variable        1
    ${checkboxindex}    Set Variable        1
    ${uncheckedbox}    Set Variable    //section[@class="${sectionClass}"]/div//input[@type="checkbox"][contains(@class, 'ng-empty')]
    ${TabName}    Set Variable    //section[@class="${sectionClass}"]/div//li/a[@class='ng-binding']
    ${count}    Get Element Count    ${uncheckedbox}
    # ${count}    Set Variable    10
    ${TabCount}    Get Element Count    ${TabName}
    ${end}    Evaluate    int(${count}+1)
    Click    (${TabName})[1]
    # ${TabEnd}    Evaluate    int(${TabCount}+1)
    FOR    ${index}    IN RANGE    1    ${end}    1
        Log    ${index}
        ${originalcount}    Get Element Count    ${uncheckedbox}
        ${status}    Run Keyword And Return Status    Get Element States    (${uncheckedbox})[${checkboxindex}]    contains    visible
        IF    '${status}' == 'True'
            Click    (${uncheckedbox})[${checkboxindex}]
            ${currentcount}    Get Element Count    ${uncheckedbox}
            IF    ${currentcount} == ${originalcount}
                ${checkboxindex}    Evaluate    int(${checkboxindex}+1)
            END
        ELSE
            ${Tabindex}    Evaluate    int(${Tabindex}+1)
            IF    ${TabCount} < ${Tabindex}
                Exit For Loop
            END
            Log    ${Tabindex}
            Click    (${TabName})[${Tabindex}]
            ${originalcount}    Get Element Count    ${uncheckedbox}
            ${visibleStatus}    Run Keyword And Return Status    Get Element States    (${uncheckedbox})[${checkboxindex}]    contains    visible
            IF    '${visibleStatus}' == 'True'
                    Click    (${uncheckedbox})[${checkboxindex}]
                    ${currentcount}    Get Element Count    ${uncheckedbox}
                    IF    ${currentcount} == ${originalcount}
                         ${checkboxindex}    Evaluate    int(${checkboxindex}+1)
                    END
            END
        END
        ${currentcount}    Get Element Count    ${uncheckedbox}
    END


Check Search Result Count in Deadline Time Report
    ${count}    Browser.Get Element Count    //table[@class='table table-striped']//tbody/tr
    Should Not Be Equal As Integers    ${count}    0
